Imports Microsoft.VisualBasic
Imports System.Web.HttpContext
Imports Framework

Public Class CSitemap

#Region "Datas"
    'List/Search
    Private Shared Function [Datas]() As String
        Return "~/pages/datas/default.aspx"
    End Function
    Public Shared Function [Datas](ByVal seriesId As Integer) As String
        Dim cols As New List(Of Integer)
        cols.Add(EData.Open)
        cols.Add(EData.Close)
        cols.Add(EData.High)
        cols.Add(EData.Low)

        cols.Add(EData.ADX)
        cols.Add(EData.ATR)
        cols.Add(EData.PlusDM)
        cols.Add(EData.MinusDM)

        cols.Add(EData.Total)
        cols.Add(EData.Held)
        cols.Add(EData.Exposure)
        cols.Add(EData.Outlook)
        cols.Add(EData.StopLong)
        cols.Add(EData.StopShort)
        cols.Add(EData.Notes)
        cols.Add(EData.Long)
        cols.Add(EData.Short)
        cols.Add(EData.LongQty)
        cols.Add(EData.ShortQty)
        cols.Add(EData.Returns)
        cols.Add(EData.PointValue)

        Dim decisions As New List(Of Integer)
        'decisions.Add(EDecision.Long)
        'decisions.Add(EDecision.Short)
        'decisions.Add(EDecision.Stop)
        Return CSitemap.Datas(seriesId, cols, decisions)
    End Function
    Public Shared Function [Datas](ByVal seriesId As Integer, ByVal columns As List(Of Integer), ByVal decisions As List(Of Integer)) As String
        Return String.Concat(CSitemap.Datas(), "?seriesId=", seriesId, "&columns=", CUtilities.ListToString(columns), "&decisions=", CUtilities.ListToString(decisions))
    End Function
    Public Shared Function [Datas](ByVal search As Integer, ByVal columns As List(Of Integer), ByVal decisions As List(Of Integer), ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Datas(search, columns, decisions), "&sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1)
    End Function
    
    'Add/Edit
    Private Shared Function DataAddEdit(ByVal columns As List(Of Integer), ByVal decisions As List(Of Integer)) As String
        Return String.Concat("~/pages/datas/data.aspx?columns=", CUtilities.ListToString(columns), "&decisions=", CUtilities.ListToString(decisions))
    End Function
    Public Shared Function DataAdd(ByVal seriesId As Integer, ByVal columns As List(Of Integer), ByVal decisions As List(Of Integer)) As String 'May require a parentId (follow pattern below)
        Return String.Concat(DataAddEdit(columns, decisions), "&seriesId=", seriesId)
    End Function
    Public Shared Function DataEdit(ByVal dataId As Integer, ByVal columns As List(Of Integer), ByVal decisions As List(Of Integer)) As String
        Return String.Concat(DataAddEdit(columns, decisions), "&dataId=", dataId)
    End Function
    Public Shared Function DataEdit(ByVal dataId As Integer, ByVal columns As List(Of EData), ByVal decisions As List(Of EDecision)) As String
        Dim c As New List(Of Integer)(columns.Count)
        For Each i As EData In columns
            c.Add(CInt(i))
        Next
        Dim d As New List(Of Integer)(decisions.Count)
        For Each i As EDecision In decisions
            d.Add(CInt(i))
        Next

        Return String.Concat(DataAddEdit(c, d), "&dataId=", dataId)
    End Function

    'UserControls
    Public Shared Function UCData() As String
        Return "~/pages//datas/usercontrols/UCData.ascx"
    End Function
    Public Shared Function UCDataHeading() As String
        Return "~/pages//datas/usercontrols/UCDataHeading.ascx"
    End Function
    Public Shared Function UCDataColumn() As String
        Return "~/pages//datas/usercontrols/UCDataColumn.ascx"
    End Function
    
    'Folders (relative to /web project)
    Public Shared Function DataUploads() As String
        Return "/uploads/datas/"
    End Function
    Public Shared Function DataImports() As String
        Return "~/app_data/imports/"
    End Function
#End Region

#Region "Seriess"
    'List/Search
    Public Shared Function [Seriess]() As String
        Return "~/pages/seriess/default.aspx"
    End Function
    Public Shared Function [Seriess](ByVal pi As CPagingInfo) As String
        Return String.Concat(CSitemap.Seriess, "?sortBy=", pi.SortByColumn, "&desc=", pi.Descending, "&p=", pi.PageIndex + 1)
    End Function
    
    'Add/Edit
    Private Shared Function SeriesAddEdit() As String
        Return "~/pages/seriess/series.aspx"
    End Function
    Public Shared Function SeriesAdd() As String 'May require a parentId (follow pattern below)
        Return SeriesAddEdit
    End Function
    Public Shared Function SeriesEdit(ByVal seriesId As Integer) As String
        Return String.Concat(SeriesAddEdit, "?seriesId=", seriesId)
    End Function

    'UserControls
    Public Shared Function UCSeries() As String
        Return "~/pages//seriess/usercontrols/UCSeries.ascx"
    End Function
    
    'Folders (relative to /web project)
    Public Shared Function SeriesUploads() As String
        Return "/uploads/seriess/"
    End Function 
#End Region

#Region "Standard"
    'Defaults
    Public Shared Function DefaultUploadsPath() As String
        Return "~/uploads/"
    End Function

    'Utilities
    Private Shared Function Encode(ByVal s As String) As String
        Return Current.Server.UrlEncode(s)
    End Function

    'Invalid ids
    Public Shared Sub RecordNotFound(ByVal entity As String)
        With HttpContext.Current.Request.QueryString
            If .Count > 0 Then RecordNotFound(entity, .Item(0)) Else RecordNotFound(entity, String.Empty)
        End With
    End Sub
    Public Shared Sub RecordNotFound(ByVal entity As String, ByVal value As Integer)
        RecordNotFound(entity, value.ToString)
    End Sub
    Public Shared Sub RecordNotFound(ByVal entity As String, ByVal pk1 As Object, ByVal pk2 As Object)
        RecordNotFound(entity, String.Concat(pk1, "/", pk2))
    End Sub
    Public Shared Sub RecordNotFound(ByVal entity As String, ByVal value As String)
        If String.IsNullOrEmpty(value) Then
            Throw New Exception(String.Concat("Invalid ", entity, "Id"))
        Else
            Throw New Exception(String.Concat("Invalid ", entity, "Id: ", value))
        End If
    End Sub
#End Region

End Class
